# ====================
# McAfee script
# ====================

from sharedDefinitions import *
import sys



f = open('D:/bwatkins/PSU/CURRENT/SWENG_500/python/McAfee.xml', 'r')

#f = open('D:/bwatkins/PSU/CURRENT/SWENG_500/python/McAfee_ALL_MALWARE.xml', 'r')

xml = f.read()

xmlLines = xml.splitlines()

html = getBlock('Virus Profile:', 'WARC/1.0', xmlLines)

#html.insert(0,'<html><head></head><body>')
#html.append('</body>')
    
clean = stripEmptyLines(html)

print '<Virus>' 

# =========================
# Get Name
# =========================
virusName = getSubStrFromList('<h1>Virus Profile:', '</h1>', clean)
##try:
##    print '  <Name>' + virusName.strip() + '</Name>'
##except AttributeError:
##    print 'Cannot parse input file. '
##    sys.exit(-1)

print '  <Name>' + virusName.strip() + '</Name>'

# =========================
# Get Alias
# =========================
aliasNameList = getBlock('<h2>Aliases</h2>', '<a shape="rect"', clean)
aliasNameStr = ''.join(aliasNameList)

a = aliasNameStr.find('<h2>Aliases</h2>') + len('<h2>Aliases</h2>')
alias = aliasNameStr[a:]
aliasList = alias.split(',')
for s in aliasList:
    print '  <Alias>' + s.strip() + '</Alias>'

# =========================
# Get DiscoveryDate
# =========================
discoverDate = getSubStrFromList('<th>Date Discovered:</th>	<td>', '</td></tr>', clean)
print '  <DiscoveryDate>' + discoverDate.strip() + '</DiscoveryDate>'


# =========================
# Get LengthInBytes 
# =========================
length = getSubStrFromList('<th>Length:</th>	<td>', '</td></tr>', clean)
print '  <LengthInBytes>' + length.strip() + '</LengthInBytes>'


# =========================
# Get GeneralComments
# =========================
description = '\nDescription: ' + getBlockReturnString('<h2>Description</h2>', '<h2>Indication of Infection</h2>', clean).strip()
indications = '\nIndication of Infection: ' + getBlockReturnString('<h2>Indication of Infection</h2>', '<h2>Methods of Infection</h2>', clean).strip()
methods = '\nMethods of Infection: ' + getBlockReturnString('<h2>Methods of Infection</h2>', '<h2>Aliases</h2>', clean).strip()
characteristics = '\nVirus Characteristics: ' + getBlockReturnString('<h2>Virus Characteristics</h2>', '<h2>Variants</h2>', clean).strip()

comments = description + indications + methods + characteristics
print '  <GeneralComments>' + stripHTML(comments) + '</GeneralComments>'

print '</Virus>'








